package il.ac.tau.cvws.scrabblesidekick.server.engine.recoginition.calibration.colorbasedcalibration.comparator;

import il.ac.tau.cvws.scrabblesidekick.shared.util.math.Point;
import il.ac.tau.cvws.scrabblesidekick.shared.util.math.Vector;

import java.util.Comparator;

/* Allows sorting of points in clockwise order, around a given anchor point.
 */
public class ClockewiseComparator implements Comparator<Point>
{
	private Point _orgPoint;
	
	public ClockewiseComparator(Point orgPoint)
	{
		_orgPoint = orgPoint;
	}
	
	@Override
	public int compare(Point p1, Point p2)
	{
		if (_orgPoint == p1)
		{
			return -1;
		}
		else if (_orgPoint == p2)
		{
			return 1;
		}
		
		Vector v1 = new Vector(_orgPoint, p1);
		Vector v2 = new Vector(_orgPoint, p2);
		
		return new Double(0.0).compareTo(v1.cross(v2).getZ());
	}
}
